package com.ruiysoft.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class TradeNoUtil {

	/**
	 * 流水号
	 * 流水号:4位随机验证码+年+月+日+时+分+秒+毫秒+4位随机验证码
	 * */
	public static String getTransactionNo(){
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		return genRandomNum(4)+sdf.format(date)+genRandomNum(4);
	}


	/**
     * 生成随机数
     *
     * @param pwd_len 密码长度
     * @return
     */
    public static String genRandomNum(int pwd_len) {
        final int maxNum = 10;
        int i;
        int count = 0;
        char[] str = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
        StringBuffer pwd = new StringBuffer("");
        Random r = new Random();
        while (count < pwd_len) {
            i = Math.abs(r.nextInt(maxNum));
            if (i >= 0 && i < str.length) {
                pwd.append(str[i]);
                count++;
            }
        }
        return pwd.toString();
    }


}
